import { Status, BaseFilter, DataScopeType } from './base';

// 部门实体
export interface Department {
  id: string;
  tenantId: string;
  organizationId: string;
  name: string;
  code: string;
  description?: string;
  parentId?: string;
  level: number;
  path: string;
  sort: number;
  status: Status;
  managerUserId?: string;
  contactInfo?: {
    email?: string;
    phone?: string;
    address?: string;
  };
  createdAt: string;
  updatedAt: string;
  createdBy?: string;
  updatedBy?: string;
  // 计算属性
  children?: Department[];
  hasChildren?: boolean;
  userCount?: number;
  positionCount?: number;
}

// 岗位实体
export interface Position {
  id: string;
  tenantId: string;
  organizationId: string;
  departmentId: string;
  name: string;
  code: string;
  description?: string;
  level: number; // 岗位级别
  category: string; // 岗位类别
  status: Status;
  requirements?: string; // 任职要求
  responsibilities?: string; // 岗位职责
  dataScope: DataScopeType; // 数据权限范围
  customDataScope?: any; // 自定义数据权限
  sort: number;
  isManager: boolean; // 是否管理岗位
  parentPositionId?: string; // 上级岗位
  salaryRange?: {
    min: number;
    max: number;
    currency: string;
  };
  createdAt: string;
  updatedAt: string;
  createdBy?: string;
  updatedBy?: string;
  // 计算属性
  userCount?: number;
  department?: Department;
}

// 部门查询过滤器
export interface DepartmentFilter extends BaseFilter {
  tenantId?: string;
  organizationId?: string;
  parentId?: string;
  level?: number;
  managerUserId?: string;
}

// 岗位查询过滤器
export interface PositionFilter extends BaseFilter {
  tenantId?: string;
  organizationId?: string;
  departmentId?: string;
  level?: number;
  category?: string;
  isManager?: boolean;
  dataScope?: DataScopeType;
}

// 部门表单数据
export interface DepartmentFormData {
  name: string;
  code: string;
  description?: string;
  parentId?: string;
  status: Status;
  managerUserId?: string;
  contactInfo?: {
    email?: string;
    phone?: string;
    address?: string;
  };
  sort?: number;
}

// 岗位表单数据
export interface PositionFormData {
  name: string;
  code: string;
  description?: string;
  departmentId: string;
  level: number;
  category: string;
  status: Status;
  requirements?: string;
  responsibilities?: string;
  dataScope: DataScopeType;
  customDataScope?: any;
  isManager: boolean;
  parentPositionId?: string;
  salaryRange?: {
    min: number;
    max: number;
    currency: string;
  };
  sort?: number;
}

// 创建部门请求
export interface CreateDepartmentRequest extends DepartmentFormData {
  tenantId: string;
  organizationId: string;
}

// 更新部门请求
export interface UpdateDepartmentRequest extends Partial<DepartmentFormData> {}

// 创建岗位请求
export interface CreatePositionRequest extends PositionFormData {
  tenantId: string;
  organizationId: string;
}

// 更新岗位请求
export interface UpdatePositionRequest extends Partial<PositionFormData> {}

// 部门树节点
export interface DepartmentTreeNode {
  id: string;
  name: string;
  code: string;
  parentId?: string;
  level: number;
  status: Status;
  userCount: number;
  positionCount: number;
  children: DepartmentTreeNode[];
  expanded?: boolean;
  selected?: boolean;
}

// 岗位层级关系
export interface PositionHierarchy {
  id: string;
  name: string;
  code: string;
  level: number;
  parentId?: string;
  children: PositionHierarchy[];
  userCount: number;
  isManager: boolean;
}

// 用户部门岗位关联
export interface UserDepartmentPosition {
  userId: string;
  departmentId: string;
  positionId: string;
  isPrimary: boolean; // 是否主部门主岗位
  assignedAt: string;
  assignedBy: string;
  // 关联信息
  department?: Department;
  position?: Position;
}